package com.shop.front.controller;

import com.shop.common.core.AjaxResult;
import com.shop.front.service.IPaperService;
import com.shop.front.validate.paper.SubmitValidate;
import com.shop.front.vo.paper.PaperDetailedVo;
import com.shop.front.vo.paper.PaperListedVo;
import com.shop.front.vo.paper.PaperLogDetailedVo;
import io.swagger.annotations.Api;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/paper")
@Api(tags = "考试相关")
public class PaperController {
    @Resource
    IPaperService iPaperService;

    /**
     * 待考试列表
     */
    @GetMapping("/unTaken")
    public AjaxResult<List<PaperListedVo>> unTaken() {
        return AjaxResult.success(iPaperService.unTaken());
    }

    /**
     * 考试详情
     */
    @GetMapping("/detail")
    public AjaxResult<PaperDetailedVo> detail(Integer id) {
        return AjaxResult.success(iPaperService.detail(id));
    }

    @GetMapping("/detail/{code}")
    public AjaxResult<PaperDetailedVo> detail(@PathVariable String code) {
        return AjaxResult.success(iPaperService.detail(code));
    }

    /**
     * 出题
     * @param paperId
     * @return
     */
    @GetMapping("/drawQuestions")
    public AjaxResult<PaperDetailedVo> drawQuestions(Integer paperId) {
        return AjaxResult.success(iPaperService.drawQuestions(paperId));
    }

    /**
     * 交卷
     */
    @PostMapping("/submit")
    public AjaxResult<Object> submit(@Validated @RequestBody SubmitValidate submitValidate) {
        iPaperService.submit(submitValidate);
        return AjaxResult.success();
    }

    /**
     * 考试记录
     */
    @GetMapping("/record")
    public AjaxResult<Object> log() {
        return AjaxResult.success(iPaperService.record());
    }

    /**
     * 考试记录详情
     */
    @GetMapping("/recordDetail")
    public AjaxResult<PaperLogDetailedVo> recordDetail(Integer logId) {
        return AjaxResult.success(iPaperService.recordDetail(logId));
    }

}
